<script setup lang="ts">
import { ref, reactive } from "vue";
import type { FormRules } from "element-plus";
import ReCol from "@/components/ReCol";
import { FormProps } from "./types";
import { usePublicHooks } from "../hooks";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    higherOptions: [], //状态其他数据,
    dictOptionData: {}, //字典数据
    noticeId: "",
    noticeTitle: "",
    noticeContent: "",
    noticeType: "",
    status: 1,
    remark: ""
  })
});

const ruleFormRef = ref();
const { switchStyle } = usePublicHooks();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}
//校验规则
const formRules = reactive(<FormRules>{
  noticeTitle: [{ required: true, message: "标题为必填项", trigger: "blur" }],
  noticeContent: [{ required: true, message: "内容为必填项", trigger: "blur" }],
  noticeType: [{ required: true, message: "类型必须选择", trigger: "blur" }]
});

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-row :gutter="30">
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="标题" prop="noticeTitle">
          <el-input
            v-model="newFormInline.noticeTitle"
            clearable
            placeholder="请输入标题"
          />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="通知类型" prop="noticeType">
          <el-select
            v-model="newFormInline.noticeType"
            class="!w-[220px]"
            placeholder="请选择通知类型"
          >
            <el-option
              v-for="(item, index) in dictOptionData['sys_notice_type']"
              :key="index"
              :label="item.dictLabel"
              :value="item.dictValue"
            />
          </el-select>
        </el-form-item>
      </re-col>

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="邮箱" prop="email">
          <el-input
            v-model="newFormInline.email"
            clearable
            placeholder="请输入邮箱"
          />
        </el-form-item>
      </re-col>

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="启用状态">
          <el-switch
            v-model="newFormInline.status"
            inline-prompt
            :active-value="0"
            :inactive-value="1"
            active-text="启用"
            inactive-text="停用"
            :style="switchStyle"
          />
        </el-form-item>
      </re-col>

      <re-col>
        <el-form-item label="备注">
          <el-input
            v-model="newFormInline.remark"
            placeholder="请输入备注信息"
            type="textarea"
          />
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>
</template>
